package dryven.unittest;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.objectweb.asm.ClassReader;

import dryven.discovery.ClassDataScanner;
import dryven.discovery.ClassDiscoveryAdapter;
import dryven.reflection.TypeRef;

public class TestGenericsReflection {

	/**
	 * @param args
	 * @throws NoSuchMethodException 
	 * @throws SecurityException 
	 */
	public static void main(String[] args) throws SecurityException, NoSuchMethodException, IOException {
		InputStream is = TestGenericsReflection.class.getResourceAsStream('/'+TestGenericsReflection.class.getName().replace('.', '/')+".class");
		ClassDataScanner scanner = new ClassDataScanner(new Listener());
		ClassReader reader = new ClassReader(is);
		reader.accept(scanner, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG);
		is.close();
	}
	
	public List<Integer> foo() {
		return null;
	}

	public int jiji() {
		return 0;
	}
}

class Listener extends ClassDiscoveryAdapter {

	@Override
	public boolean onMethod(int access, String typeName, String methodName,
			TypeRef[] types, TypeRef returnType) {
		if(returnType==null) {
			return false;
		}
		System.out.println(String.format("Method %s returns a %s with generic parameters:", methodName,returnType.getTypeName()));
		if(returnType.getGenericTypeParams()!=null) {
			for (TypeRef typeValue : returnType.getGenericTypeParams()) {
				System.out.println(typeValue.getTypeName());
			}
		}
		return false;
	}
	
}
